package com.example.demo;

//import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.*;

@ComponentScan(basePackages = {"com.ruoyi","com.example"})
//@MapperScan("com.ruoyi.**.mapper")
@SpringBootApplication
@RestController
public class DemoApplication {

    public static void main(String[] args) {
        //System.out.println("hello world 3");
        SpringApplication.run(DemoApplication.class, args);
        System.out.println("hello world main");
    }

    // http://localhost:8080/hello?name=abc
//    @GetMapping("/hello")
    @GetMapping(value = "/hello", produces = "application/json;charset=utf8")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        System.out.println("/hello  name="+name);

        return String.format("Hello  %s!", name);
//        return "{\"name\": \""+name+"\"}";
//        throw new CustomException("卧槽！！出错了");
    }

    
//	// http://localhost:8080/list?name=list1
//    @GetMapping("/list")
//    public String list(@RequestParam(value = "name", defaultValue = "World") String name) {
//    	return String.format("List 1  %s!", name);
//    }


    @RestControllerAdvice
    public class GlobalExceptionHandler {
        //自定义异常处理器
        @ExceptionHandler(CustomException.class)
        public String CustomExceptionHandler(Exception e) {
            return "{\"msg\": \""+e.getMessage()+"\"}";
        }
    }


}



class CustomException  extends  RuntimeException{

    public CustomException(String message) {
        super(message);
    }
}


